﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Skynet.WebAdministracion.Views.DesignStartExam;
using Microsoft.Practices.Unity;

namespace Skynet.WebSite.Administration
{
    public partial class DesignStartExamView : Infrastructure.Web.Views.Page, IDesignStartExamView
    {
        private DesignStartExamPresenter _Presenter;

        [Dependency]
        public DesignStartExamPresenter Presenter
        {
            get { return _Presenter; }
            set
            {
                _Presenter = value;
                this._Presenter.View = this;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {            
            this.odsQuestions.ObjectCreating += delegate(object ocds, ObjectDataSourceEventArgs args) { args.ObjectInstance = this.Presenter; };

            
            if (!Page.IsPostBack)
            {
                this.Presenter.OnViewInitialized();
            }
            else
                this.Presenter.OnViewLoaded();
        }

        

        public Guid CategoryId
        {
            get
            {
                return Guid.Parse(this.ddlCategory.SelectedValue);
            }
            set
            {                
                var items = this.ddlCategory.Items;                
                foreach (ListItem item in items)                
                {
                    if (item.Value == value.ToString())
                        item.Selected = true;
                    else
                        item.Selected = false;
                }
            }
        }
        public IEnumerable<BusinessEntities.ExamCategory> Categories
        { 
            set {
                this.ddlCategory.DataSource = value;
                this.ddlCategory.DataBind();
            } 
        }
        public string Summary { get { return this.txtSummary.Text; } set { this.txtSummary.Text = value;} }
        public string ExamTitle { get { return this.txtTitle.Text; } set { this.txtTitle.Text = value; } }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if ( this.gvQuestions.SelectedValue != null)
                this.Presenter.SelectQuestion((Guid)this.gvQuestions.SelectedValue );
        }

        protected void lbBackExams_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid) return;
                this.Presenter.BackToExams();
        }
        protected void lbGenerateQuestion_Click(object sender, EventArgs e)
        {
            if ( !Page.IsValid)
                this.Presenter.GenerateQuestions();
        }
        protected void odsQuestions_Deleted(object sender, ObjectDataSourceStatusEventArgs e)
        {

        }


    
    }
}